<?php
namespace app\manage\controller;
class GameServer extends Base
{
    public function index(){
        if( request()->isAjax() ){
            $page = input('page');
            $limit = input('limit');
            $gameId = input('game_id');

            $where['status'] = 1;
            !empty($gameId) && $where['game_id'] = $gameId;

            if( ! $count=model('GameServer')->where($where)->count() ){
                $this->layTable();
            }

            $select = model('GameServer')
                ->field('game_id,server_id,server_name,open_time,status')
                ->where($where)
                ->order('open_time desc')
                ->limit(($page-1)*$limit, $limit)
                ->select();

            $data = [];
            $gameIdName = model('Game')->gameIdName();
            foreach ($select as $k=>$v){
                $data[] = [
                    'game_id' => $v['game_id'],
                    'game_name' => $gameIdName[ $v['game_id'] ],
                    'server_id' => $v['server_id'],
                    'server_name' => $v['server_name'],
                    'open_time' => date('Y-m-d H:i:s', $v['open_time']),
                    'status' => $v['status'] ? '启用' : '禁用',
                ];
            }
            $this->layTable(0, '区服列表', $data, $count);
        }else{
            return view();
        }
    }
}